"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const enums_1 = require("../utils/enums");
function default_1(app) {
    const { socket, rooms } = app.locals;
    const { userId, username } = socket.handshake.query;
    socket.on('notice', function (data, cb) {
        console.log('退订', data.userId);
        if (data.userId === userId) {
            cb('ffffffffffffffff----');
        }
    });
    socket.on('onlineUsers', function (cb) {
        const { members } = app.locals;
        if (cb) {
            cb({ status: 'ok', members: Object.values(members).map((member) => member.json()) });
        }
    });
    socket.on('gainSpeak', function (data, cb) {
        const { classId } = data.room;
        const __room = rooms[classId] || {};
        if (__room.type === enums_1.ChatModeEnums.INTERCOM && __room.speaker === null) {
            socket.broadcast.to(data.roomId).emit('gainSpeak', { member: { userId, username } });
            cb && cb({ status: 'ok' });
        }
        else {
            cb && cb({ status: 'fail', member: __room.speaker });
        }
    });
    socket.on('freeSpeak', function (data, cb) {
        const { classId } = data.room;
        const __room = rooms[classId] || {};
        if (__room.type === enums_1.ChatModeEnums.INTERCOM && __room.speaker !== null) {
            socket.broadcast.to(data.roomId).emit('freeSpeak', { member: { userId, username } });
            cb && cb({ status: 'ok' });
        }
        else {
            cb && cb({ status: 'fail', member: __room.speaker });
        }
    });
}
exports.default = default_1;
